
<?php include 'inc/header.php'; ?>

<?php
  $name = $email = $courseName = $content = '';
  $nameErr = $emailErr = $courseNameErr = $contentErr = '';

  if (isset($_POST['submit'])) {
    if (empty($_POST['name'])) {
      $nameErr = "姓名必须填" ;
    } else {
      $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    }

    if (empty($_POST['email'])) {
      $nameErr = "邮箱必须填";
    } else {
      $name = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    }

    if (empty($_POST['course'])) {
      $nameErr = "课程必须填";
    } else {
      $name = filter_input(INPUT_POST, 'ecourse', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    }

    if (empty($_POST['body'])) {
      $nameErr = "评价内容必须填";
    } else {
      $name = filter_input(INPUT_POST, 'body', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    }
  }
  

?>

    <img src="/course-review-app/img/logo.png" class="w-25 mb-3" alt="">
    <h2>课程评价</h2>
    <p class="lead text-center">为你所上的课程留下评价</p>
    <form action="" class="mt-4 w-75">
      <div class="mb-3">
        <label for="name" class="form-label">你的姓名</label>
        <input type="text" class="form-control <?php echo $nameErr ? 'is-invalid' : null; ?>" 
        id="name" name="name" placeholder="请输入你的姓名">
        <div class="invalid-feedback">
            <?php echo $nameErr; ?>
        </div>
      </div>
      <div class="mb-3">
        <label for="email" class="form-label">你的邮箱</label>
        <input type="email" class="form-control <?php echo $nameErr ? 'is-invalid' : null; ?>" 
        id="email" name="email" placeholder="请输入你的邮箱">
        <div class="invalid-feedback">
            <?php echo $nameErr; ?>
        </div>
      </div>
      <div class="mb-3">
        <label for="course" class="form-label">课程名称</label>
        <input type="text" class="form-control <?php echo $nameErr ? 'is-invalid' : null; ?>" 
        id="course" name="course" placeholder="请输入你的课程名称">
        <div class="invalid-feedback">
            <?php echo $nameErr; ?>
        </div>
      </div>
      <div class="mb-3">
        <label for="body" class="form-label">评价内容</label>
        <input type="text" class="form-control <?php echo $nameErr ? 'is-invalid' : null; ?>" 
        id="body" rows="4" placeholder="请输入你的评价">
        <div class="invalid-feedback">
            <?php echo $nameErr; ?>
        </div>
      </div>
      <div class="mb-3">
        <input type="submit" name="submit" value="提交评价" class="btn btn-dark w-100">
      </div>
    
    </form>
    

    <?php include 'inc/footer.php'; ?>